package com.zi.experttalk.experttalk.Model.service;

import android.app.AlertDialog;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import com.zi.experttalk.experttalk.R;

import java.util.List;

/**
 * Created by Administrator on 2014/12/16.
 */
public class AlterDialogManager {
    private AlertDialog.Builder builder;
    private  AlertDialog alertDialog;
    public void setAlterDialog(final Context context, final List<String> list, final Button button, final GetSelecterListener getSelecterListener){
        View view = LayoutInflater.from(context).inflate(R.layout.alterdialog_list,null);
        final ListView listView = (ListView) view.findViewById(R.id.list);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,R.layout.alterdialog_list_item,list);
        listView.setAdapter(adapter);
        builder = new AlertDialog.Builder(context);
        alertDialog = builder.create();
        alertDialog.setView(view);
        alertDialog.show();
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String data =parent.getItemAtPosition(position).toString();
                Log.d("Item的内容",data);
                getSelecterListener.onResultListener(data);
                button.setText(data);
                alertDialog.dismiss();
            }
        });
    }
    public interface  GetSelecterListener{
        public void onResultListener(String selecterItem);
    }
}
